package top.soulblack.purchasesale.mapper;

import org.apache.ibatis.annotations.*;
import top.soulblack.purchasesale.model.Customer;
import top.soulblack.purchasesale.model.Supplier;

import java.util.List;

/**
 * @Author: 陈俊宇
 * @Description:客户管理
 * @Date: Create in 15:01 2019/8/30
 */

@Mapper
public interface CustomerMapper {
    @Select("select * from customer order by sort")
    List<Customer> selectAll();

    @Insert("insert into customer (name,mobile_phone, phone, mail, nickname,contacts,status,sort,fax,bank_account,bank_number" +
            ",open_bank,discount,membership_card, sex, address, remark, debt, type, integral, birthday ) values (" +
            "#{name}, #{mobilephone}, #{phone}, #{mail},#{nickname}, #{contacts}, #{status}, #{sort}, #{fax}, #{bankaccount}, #{banknumber}," +
            " #{openbank}, #{discount}, #{membershipcard}, #{sex},#{address}, #{remark}, #{debt}, #{type}, #{integral}, #{birthday})")
    void addCustomer(Customer customer);

    @Select("select count(*) from customer where name = #{name}")
    int existCustomer(String name);

    @Delete("delete from customer where id = #{customersId}")
    int deleteById(Integer customersId);

    @Select("select * from customer where name = #{name}")
    List<Customer> selectForName(@Param("name") String name);

    @Update("update customer set name=#{name}, mobile_phone=#{mobilephone}, phone=#{phone}, mail=#{mail},nickname=#{nickname}, contacts=#{contacts},  status=#{status}" +
            ",sort= #{sort}, fax=#{fax}, bank_account=#{bankaccount}, bank_number=#{banknumber},open_bank= #{openbank}, discount=#{discount}, membership_card=#{membershipcard},membership_card= #{membershipcard},  " +
            " address=#{address}, remark=#{remark}, debt=#{debt}, integral=#{integral}, type=#{type}, birthday=#{birthday} where id=#{id}")
    int updateCustomer(Customer customer);
}

